package com.bw.ivideoproject

import android.content.Intent
import android.graphics.Color
import android.os.CountDownTimer
import android.view.View
import com.blankj.utilcode.util.SPUtils
import com.bw.ivideoproject.databinding.ActivitySplashBinding
import com.bw.ivideoproject.login.LoginActivity
import com.bw.lib_mvvm.BaseActivity

class SplashActivity : BaseActivity<ActivitySplashBinding>() {

    private lateinit var timer:CountDownTimer
    private var count = 3
    override fun initView() {

        timer = object : CountDownTimer(3000,1000){
            override fun onTick(p0: Long) {
                binding.tvCountDown.text = count.toString()
                count --
            }

            override fun onFinish() {
                val token = SPUtils.getInstance().getString("token")
                if(token.isNullOrEmpty()){
                    startActivity(Intent(this@SplashActivity,LoginActivity::class.java))
                }else{
                    startActivity(Intent(this@SplashActivity,MainActivity::class.java))
                }
                this@SplashActivity.finish()
                cancel()
            }
        }.start()
    }

    override fun onDestroy() {
        super.onDestroy()
        timer.cancel()
    }

    override fun initData() {

    }

    override fun bindLayout(): Int {
        return R.layout.activity_splash
    }


}